package com.jackstraw.jack_base.rules.service.impl;

import com.jackstraw.jack_base.datasource.common.aspect.annotation.DataSourceNameCut;
import com.jackstraw.jack_base.datasource.common.entity.enums.DataSourceTypeEnum;
import com.jackstraw.jack_base.datasource.mybatis.base.service.impl.MyBatisServiceImpl;
import com.jackstraw.jack_base.rules.dao.database.RelationRgrDao;
import com.jackstraw.jack_base.rules.entity.bo.RelationRgrBo;
import com.jackstraw.jack_base.rules.entity.mapstruct.RelationRgrMapstruct;
import com.jackstraw.jack_base.rules.entity.po.RelationRgrKeyPo;
import com.jackstraw.jack_base.rules.entity.po.RelationRgrPo;
import com.jackstraw.jack_base.rules.entity.po.RelationRgrPoExample;
import com.jackstraw.jack_base.rules.service.RelationRgrService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 规则组规则关系表  service实现类
 *
 * @author zhaozhao 945514650@qq.com
 * @since version:1.0 generatorDate:2022-12-04 14:28:29
 */
@Slf4j
@DataSourceNameCut(dataSourceName = "dataBaseName1", dataSourceTypeEnum = DataSourceTypeEnum.database)
public class RelationRgrServiceImpl
        extends MyBatisServiceImpl<RelationRgrDao, RelationRgrPo, RelationRgrBo, RelationRgrKeyPo<RelationRgrPo>, RelationRgrPoExample>
        implements RelationRgrService {


    @Autowired
    private RelationRgrMapstruct relationRgrMapstruct;


    @Override
    protected RelationRgrPoExample pe(Map<String, Object> params) {
        RelationRgrPoExample pe = super.pe(params);
        //默认查询主键
        pe.addKey(params);
        return pe;
    }


    @Override
    public List<RelationRgrBo> queryByRuleGroupId(Long ruleGroupId) {
        RelationRgrPoExample relationRgrPoExample = new RelationRgrPoExample();
        relationRgrPoExample.createCriteria()
                .andRgrRelationIdEqualTo(ruleGroupId);
        List<RelationRgrPo> relationRgrPos = this.getDao().selectByExample(relationRgrPoExample);
        return relationRgrMapstruct.boToS(relationRgrPos);
    }
}
